package cn.com.zpark.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.cookie
 * @ClassName: CookieDemo02
 * @Description:
 * @author: RZS
 * @date: 2021/11/15  14:51
 */
@WebServlet("/cd2.do")
public class CookieDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 获取请求头中包含的Cookie信息
         */
        // 获取cookie
        Cookie[] cookies = request.getCookies();
        // 循环从cookies数组中取出每一个cookie对象
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getMaxAge());
            System.out.println(cookie.getName()+": "+cookie.getValue());
            System.out.println(cookie.getPath());
            System.out.println(cookie.getSecure());
            System.out.println(cookie.getVersion());
            System.out.println("********************************");
        }
    }
}
